package com.ophiux;


import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;


@SpringBootApplication(exclude = {SecurityAutoConfiguration.class,  ManagementWebSecurityAutoConfiguration.class})
public class ActivitiApplication {
    public static void main(String[] args) {
        //方式一
//        initDataBase();

        //方式二：默认会加载resources/activiti.cfg.xml
//        initDataBase2();

        SpringApplication.run(ActivitiApplication.class, args);
        System.out.println("https://www.activiti.org/quick-start");
        System.out.println("Hello world!");
    }

    /**
     * 直接运行导入工作流需要的表
     */
    public static void initDataBase() {
        ProcessEngineConfiguration config = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();

        // 连接数据库的配置
        config.setJdbcDriver("com.mysql.cj.jdbc.Driver");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/activiti?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&nullCatalogMeansCurrent=true");
        config.setJdbcUsername("root");
        config.setJdbcPassword("root");
        //检查数据库是否有表，没有才创建
        config.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        //工作流的核心对象，ProcessEnginee对象
        ProcessEngine processEngine = config.buildProcessEngine();
        System.out.println("processEngine:" + processEngine);
    }

    @Test
    public void initDataBase2(){
        //默认会加载resources/activiti.cfg.xml
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        System.out.println(processEngine);
    }
}